<?php
namespace app\admin\model;

use think\Model;

class ProAttrModel extends Model
{
	// 确定链接表名
    protected $name = 'product_attr';

    /**
	 * [获取所有产品属性]
     */
    public function getAttrList(){
    	return $this->select();
    }

    /**
	 * [添加产品属性]
     */
    public function addAttr($param){
    	if($this->insert($param)){
    		return ['code'=>1,'msg'=>'添加成功'];
    	}else{
    		return ['code'=>0,'msg'=>'添加失败'];
    	}
    }

    /**
	 * [编辑产品属性]
     */
    public function editAttr($param){
    	try{
    		$this->where('id',$param['id'])->update($param);
    		return ['code'=>1,'msg'=>'编辑成功'];
    	}catch(Exception $e){
    		return ['code'=>0,'msg'=>'编辑失败'.$e->getMessage()];
    	}
    }

    /**
	 * [删除产品属性]
     */
    public function delAttr($param){
    	if($this->where('id',$param)->delete()){
    		return ['code'=>1,'msg'=>'删除成功'];
    	}else{
    		return ['code'=>0,'msg'=>'删除失败'];
    	}
    }

    /**
	 * [获取产品属性]
     */
    public function getAttrByPid($pid){
    	return $this->where(['pid' => $pid])->select();
    }
}